<?php

/**
 *
 * @author ben <ben@spicatech.cn>  Created on 2015-8-30
 */
class ExamItemList extends ListObject {

    public function get() {
        $model = ExamItem::model();
        $table = $model->tableName();
        $c = $this->getCriteria();

        $list = $model->getDbConnection()
                ->createCommand()
                ->select()
                ->from($table)
                ->where($c->condition, $c->params)
                ->limit($this->condition->pageSize,($this->condition->page - 1) * $this->condition->pageSize)
                ->queryAll();
        foreach ($list as $k => $v) {
            $v['item_answer_pool'] = json_decode($v['item_answer_pool']);
            if(!$v['item_answer_pool']) {
                $v['item_answer_pool'] = array();
            }
            $list[$k] = $v;
        }
        return $list;
    }

    public function count() {
        $c = $this->getCriteria();
        return ExamItem::model()->count($c);
    }

    public function getCriteria() {
        $c = new CDbCriteria();
        $c->addColumnCondition(array('client_id' => $this->condition->clientId));
        
        return $c;
    }

}
